﻿using Future.Common.Models;
using System.Linq.Expressions;

namespace Future.IDAL
{
    /// <summary>
    /// 所有基础的便捷的数据访问接口(SQL操作的都不在此范围内)
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IBaseDAL<T> where T : class, new()
    {
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        Task<bool> InsertAsync(T model);

        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        bool Insert(T model);

        /// <summary>
        /// 批量插入
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        Task<bool> InsertManyAsync(List<T> models);

        /// <summary>
        /// 批量插入
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        bool InsertMany(List<T> models);

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        Task<bool> UpdateAsync(T model);

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        bool Update(T model);

        /// <summary>
        /// 批量更新
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        Task<bool> UpdateManyAsync(List<T> models);

        /// <summary>
        /// 批量更新
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        bool UpdateMany(List<T> models);

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        Task<bool> DeleteAsync(T model);

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        bool Delete(T model);

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        Task<bool> DeleteAsync(Expression<Func<T, bool>> where);

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        bool Delete(Expression<Func<T, bool>> where);

        /// <summary>
        /// 单表多条件查询
        /// </summary>
        /// <param name="pars"></param>
        /// <returns></returns>
        Task<T> GetAsync(Expression<Func<T, bool>> where);

        /// <summary>
        /// 单表多条件查询
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        T Get(Expression<Func<T, bool>> where);

        /// <summary>
        /// 单表多条件查询
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        Task<List<T>> GetListAsync(Expression<Func<T, bool>> where);

        /// <summary>
        /// 单表多条件查询
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        List<T> GetList(Expression<Func<T, bool>> where);

        /// <summary>
        /// 单表查询通用分页
        /// </summary>
        /// <param name="where">lambda条件</param>
        /// <param name="page">分页参数</param>
        /// <returns></returns>
        PageModel<T> PageList(Expression<Func<T, bool>> where, PageParModel page);

        /// <summary>
        /// 单表查询通用分页
        /// </summary>
        /// <param name="where">lambda条件</param>
        /// <param name="page">分页参数</param>
        /// <param name="orderBy">排序字段</param>
        /// <returns></returns>
        Task<PageModel<T>> PageListAsync(Expression<Func<T, bool>> where, PageParModel page, string? orderBy = null);
    }
}